<extend name="Public/layout"/>
<block name="head">
<link rel="stylesheet" href="__PUBLIC__css/wx-register.css">
<style type="text/css">
.footer{
    display: none;
}
</style>
</block>
<block name="main">
    <div class="banner">
        <img src="__PUBLIC__images/register-banner-1.png" alt="">
    </div>

    <div class="form">
        <div class="form-group">
            <input type="text" name="tel"  class="phone-number" placeholder="请输入您的手机号码">
        </div>
        <div class="form-group">
            <input type="text"  name="img_code" class="verify-code" placeholder="请输入图形验证码">
            <div class="verify-code-wrapper" style="background-color: #999999;">
	            <img src="/home/user/img_verify" width="100%" height="100%" onclick="newgdcode(this);">
            </div>
        </div>
        <div class="form-group">
            <input type="text" name="code"  class="phone-text" placeholder="请输入您的短信验证码">
            <div class="phone-text-wrapper">
                <button class="get-verify-code" send="0" onclick="getcode(this)">获取验证码</button>
            </div>
        </div>
    </div>

    <div class="form">
        <div class="form-group">
            <input type="password" name="password"  placeholder="请设置新的登录密码">
        </div>
        <!--<div class="form-group">
            <input type="password" name="password_f" placeholder="请确认新的登录密码">
        </div>-->
    </div>

    <div class="btn-wrapper">
        <a href="javascript:" onclick="sub()">确认绑定</a>
    </div>
</body>
</block> 
<block name="js">
<script>
		function newgdcode(obj){
          var url = '/home/user/img_verify/time/'+ new Date().getTime()
          $(obj).attr('src',url);
        }
		
		var checkphone=false;
        function check_phone(){
             var phone = $('input[name="tel"]').val();
             if(!(/^1\d{10}$/.test(phone))){ 
                  msg = "请输入11位数的手机号码";
                  checkphone=false;
                  layer.open({
                    content:msg
                    ,skin: 'msg'
                    ,time: 1 //2秒后自动关闭
                  });
				  return;
             }else{
                checkphone=true;
             }

              $.post("{:U('User/checkphone')}",{
                phone:phone,
              },function(res){
                if(res.err==1){
                   checkphone =false;
                     layer.open({
                        content: '该手机号码已注册！'
                        ,skin: 'msg'
                        ,time: 1 //2秒后自动关闭
                      });
                }else{
                    checkphone=true;
                }
              })


        }

        //获取验证码
        function getcode(obj){
             var phone = $('input[name="tel"]').val();
             if(!(/^1\d{10}$/.test(phone))){ 
                  msg = "请输入11位数的手机号码";
                  checkphone=false;
                  layer.open({
                    content:msg
                    ,skin: 'msg'
                    ,time: 1 //2秒后自动关闭
                  });
				  return;
             }else{
                  $.post("{:U('User/checkphone')}",{
					phone:phone,
				  },function(res){
					if(res.err==1){
					   checkphone =false;
						 layer.open({
							content: '该手机号码已注册！'
							,skin: 'msg'
							,time: 1 //2秒后自动关闭
						  });
					}else{
						var send = $(obj).attr('send');
						var imgcode = $('.verify-code').val();
						if(!imgcode){
							layer.open({
							content: '请输入图形验证码！'
							,skin: 'msg'
							,time: 1 //2秒后自动关闭
						  });
						}
						if(send && imgcode){
							event_send_sms()
						}
					}
				  })
             }

            
			  
       
            
        }

          //验证码计时
        var timer = 60;
        function codeTimer()
        {
            timer--;
            if(timer > 0){
                $('.get-verify-code').text( timer + '秒后可重发!');
                $('.get-verify-code').attr("send",1);
                setTimeout('codeTimer()', 1000);
            }else{
                $('.get-verify-code').text('获取验证码');
                $('.get-verify-code').attr("send",0);
                timer = 60;
            }
        }

        //发送短信
        function event_send_sms(){
            var postData={
                phone: $('input[name="tel"]').val(),
                code_img:$("input[name='img_code']").val()
            }
            if(timer >= 60){
                var phone = $("#phoneN").val();
                    $(this).attr('disabled', 'disabled');
                    $.ajax({
                        url:'{:U("Sms/send_sms_reg")}',
                        data:postData,
                        type:"post",
                        dataType:"json",
                        success:function(d){
                            if(d.err == 0){
                                codeTimer();
                            }else{
                                 layer.open({
                                    content: d.msg
                                    ,skin: 'msg'
                                    ,time: 1 //2秒后自动关闭
                                  });
                            }
                        }
                    });
                
            }
        }
			
	function sub(){
	 
		var phone = $('input[name="tel"]').val();
		var code = $('input[name="code"]').val();
			
        var password = $('input[name="password"]').val()
       
			var password=$.md5(password);
		
		 $.post("{:U('User/checkphone')}",{
                phone:phone,
              },function(res){
			
                if(res.err==1){
                     layer.open({
                        content: '该手机号码已注册！'
                        ,skin: 'msg'
                        ,time: 1 //2秒后自动关闭
                      });
					  return false;
                }else{
                   $.post('{:U("User/wechat_regist")}',{
						password:password,
						phone:phone,
						code:code,
					},function(res) {
					 console.log(res)
							if(res.err==0){
								layer.open({
									content:res.msg
									,skin: 'msg'
									,time: 1
									,end:function(){
										//location.href="/Home/User/circle"
										location.href="/Home/User/master"
									}
								});
							}else{
								layer.open({
								content:res.msg
								,skin: 'msg'
								,time: 1
							})
							
						};
			   
					})
				   
				   
                }
              })  
			  
        // $.md5(password);
	
      
			
	}
	
	
		
    // 绑定成功弹框
    var h = '';
    h += '<div class="wx-bangding-result-layer">'
    h += '<div class="content-wrapper">'
    h += '<h4>绑定成功</h4>'
    h += '<p class="text">您已成功绑定8金融街账号</p>'
    h += '</div></div>'

    function successLayer() {
        layer.open({
            type: 1
            ,content: h
            ,btn: ['确定']
            ,yes: function (index) {
            }

        })
    }

    // 绑定失败弹框
    var h1 = '';
    h1 += '<div class="wx-bangding-result-layer">'
    h1 += '<div class="content-wrapper">'
    h1 += '<h4>绑定失败</h4>'
    h1 += '<p class="text">您的账号已被绑定</p>'
    h1 += '</div></div>'

    function errorLayer() {
        layer.open({
            type: 1
            ,content: h1
            ,btn: ['重新绑定']
            ,yes: function (index) {
            }
        })
    }
</script>
</block>